const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const config = {
  mode: 'production',
  entry: './src/index.js',
  output: {
    // path.join() 去拼接路径
    // __dirname 当前文件的绝对路径
    filename: 'bundle.js',
    path: path.join(__dirname, './dist')
  },
  resolve: {
    alias: {
      '@assets': path.join(__dirname, './src/assets')
    }
  },
  module: {
    rules: [
      {
        // sass-loader node-sass两个依赖都需要安装
        test: /\.(scss|sass)$/,
        use: ['style-loader', 'css-loader', 'sass-loader']
      },
      {
        test: /\.(png|jpg)$/,
        use: [
          {
            loader: "file-loader",
            options: {
              esModule: false
            }
          }
        ]
      }
    ]
  },
  plugins: [
      new HtmlWebpackPlugin({
        filename: "index.html",
        template: path.join(__dirname, './template.html')
      })
  ]
}

module.exports = config